package com.itheima.Controller;

import com.itheima.Service.OrderService;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderDetails;
import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/orders")
public class OrderController {
    @Autowired
    private OrderService orderService;
//    @GetMapping
//    private Result list(@RequestParam(defaultValue = "1") Integer page,
//                        @RequestParam(defaultValue = "10") Integer pageSize,
//                        int userId,String status,
//                        @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
//                        @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
//        log.info("调用查询所有订单接口,{},{},{},{},{},{}",page,pageSize,userId,status,begin,end);
//        return Result.success();
//    }
    @GetMapping
    private Result getOrders(){
        log.info("调用查询所有订单接口");
        List<Order> orderList = orderService.getOrders();
        return Result.success(orderList);
    }
    @GetMapping("/{id}")
    private Result getOrderDetails(@PathVariable int id){
        log.info("调用查询订单详情接口,{}",id);
        OrderDetails orderDetails = orderService.getOrderDetailsById(id);
        return Result.success(orderDetails);
    }
}
